package com.example.fw;

import org.openqa.selenium.By;

/**
 * Created with IntelliJ IDEA.
 * User: pshevchenko
 * Date: 06.03.13
 * Time: 18:52
 * To change this template use File | Settings | File Templates.
 */
public class NavigationHelper extends WebDriverHelperBase {

    private boolean onMainPage() {
        return (driver.findElements(By.id("maintable")).size() > 0);
    }

    private boolean onGroupList() {
        return ((driver.getCurrentUrl().contains("/group.php"))
                && (driver.findElements(By.name("new")).size() > 0));
    }

    private boolean onPrintPhone() {
        return (driver.getCurrentUrl().contains("/view.php?all&print&phones"));  //To change body of created methods use File | Settings | File Templates.
    }

//----------------------------------------------------------------------------------------------------------------------

    public NavigationHelper(ApplicationManager manager) {
        super(manager);
    }

    public NavigationHelper reloadApp(){
        driver.get(manager.baseUrl);
        return this;
    }

    public NavigationHelper mainPage() {
        if (!onMainPage())
            clickElement(By.linkText("home"));
        return this;
    }

    public NavigationHelper groupsList() {
        if (!onGroupList())
            clickElement(By.linkText("groups"));
        return this;
    }

    public NavigationHelper printPhonePage() {
        if (!onPrintPhone())
            clickElement(By.linkText("print phones"));
        return this;
    }
}
